#ifndef Manager_First
#define Manager_First
#ifdef __GNUG__
#pragma interface
#endif

#include "EvtHandler.h"
#include "WindowSystem.h"
#include "Window.h"

class Menu;
class ObjList;
class CommandProcessor;
class Application;
class Window;
class Command;
class MenuBar;
class VObject;
class Button;
class Token;
class OrdCollection;
class TextViewOverlay;

enum MgrDismiss {
	eMgrClose,
	eMgrHide,
	eMgrIconize
};

//---- Manager -----------------------------------------------------------------

class Manager : public EvtHandler {
public:
	MetaDef(Manager);

	Manager(const char *title= 0, MgrDismiss md= eMgrHide, WindowType wt= eWinStandard);
	Manager(Manager*, const char *title= 0, MgrDismiss md= eMgrHide, WindowType wt= eWinStandard);
	~Manager();

	//---- misc
	void Init(Manager*, const char *name, MgrDismiss oc, WindowType wt);
	virtual void SetName(const char *name);
	virtual const char *GetName();
	bool IsEqual(Object*);
	bool IsOpen()
		{ return isopen; }
	void CollectParts(Collection*);
	void InspectorId(char *buf, int bufSize);

	//---- change management
	CommandProcessor *GetCmdP();
	virtual CommandProcessor *MakeCmdProcessor();
	void ClearCmdProcessor();
	void SetCmdProcessor(CommandProcessor *c);

	//---- managers
	virtual void Open();

	void OpenAt(VObject *fp, Point p, bool resize= FALSE, bool block= FALSE);
	virtual int ShowAt(VObject *fp, Point p, bool resize= FALSE, bool block= FALSE);
	virtual void Show();
	int ShowUnderMouse();
	int ShowOnWindow(VObject *fp);

	virtual bool Close();       // return TRUE if OK
	virtual int Run();
	void Hide();
	void HideAndRemember();
	void Unhide();
	virtual void AboutToOpen();
	virtual bool AboutToDismiss();
	bool Dismiss();
	virtual void Iconize();

	Iterator *MakeIterator(void *placement= 0);
	int Size();
	virtual void AddManager(Manager*);
	virtual void RemoveManager(Manager*);
	virtual Manager *FindManager(u_long id);
	void SetNextManager(Manager *mp);
	EvtHandler *GetNextHandler();
	virtual u_long UniqueId();

	//---- events
	void InputKbd(Token &t);
	bool SetFirstHandler(EvtHandler *eh);
	EvtHandler *GetFirstHandler()
		{ return firstHandler; }
	Button *GetDefaultButton();
	void TabFields(Token &t);
	void ExtCommand(int from, char *req, char *args, int len, char *&ret, int &retlen);
	void Control(int id, int part, void *vp);
	void SendDown(int id, int part, void *val);
	TextViewOverlay *GetTextViewOverlay();

	//---- windows
	virtual Window *DoMakeWindows();
	virtual VObject *DoMakeContent();
	virtual VObject *DoMakeIconContent();
	virtual void MakeWindows();
	virtual Point GetInitialPos(Point e);
	virtual Point GetInitialWindowPos();
	virtual Point GetInitialWindowSize();
	virtual void SetWindowTitle(const char *title);
	Window *GetWindow();
	void SetOnDismiss(MgrDismiss md);

	//---- menues
	virtual MenuBar *DoMakeMenuBar();
	virtual Menu *MakeMenu(int menuId);
	void DoSetupMenu(Menu*);
	Command *DoMenuCommand(int);
	void PerformCommand(Command*);
	Menu *GetMenu();
	MenuBar *GetMenuBar();

protected:
	WindowType wtype;
	WindowFlags wflags;
private:
	Manager *nextManager;
	OrdCollection *managers;
	Menu *menu;
	MenuBar *menubar;
	Window *window;
	EvtHandler *firstHandler;
	CommandProcessor *cmdp;
	MgrDismiss dismiss;
	char *name;
	TextViewOverlay *tvo;
	bool isopen, wasopen;
};

#endif

